﻿/*
  @Description:房源详情页跟进页js
  @Author:zb,yangpl
  @Date:2014-07-22 
  此方法同时被房源列表页引用,所以不要加任何pageload类型事件
*/
var proertyFollow = {};
var proertydetailfollow = proertyFollow;//对象别名，用于tabmenu.js,tabmenu.js会去调用proertydetailfollow.init
$(function () {
    agencyVerify.nonnegativeIntInput("input[isint=1]", true);
    agencyVerify.nonnegativeInput("input[isfloat=1]", true);

});
//取消置顶方法
proertyFollow.CannelTop = function (element) {
    //判断权限
    //if (!PropertyFollowRight.CheckTopRightDedail()) {
    //    return;
    //}
    var id = $(element).attr("followid");
    var content = $(element).attr("content");
    $.AjaxAgency('/Property/property-follow-mark-top-cancel-ajax', { 'keyid': id, 'propertyKeyId': $("#hidPropertyKeyId").val(), 'followContent': content }, function (data) {
        if (data == "OK") {
            $.OKDialogAgency('<div class="tc">取消成功</div>', '提示', function () {
                $("#hidrandom").val(Math.random);
                $("#searchForm").submit();
                $("#btnTop,#btnDel").removeClass("btn-blue2").addClass("btn-gray");
            });
        }
        else {
            $.OKDialogAgency('<div class="tc">取消出错:' + data + '</div>');
        }
    });
};

proertyFollow.delDynamicItem = function (e) {
    $(e).parent().remove();
};
//售价
proertyFollow.ShowSalePrice = function () {
    $("#sPriceSpan").css("display", "");
    $("#rPriceSpan").css("display", "none");
    $("#rPriceSpan #rentPrice").val("");
};
//租价
proertyFollow.ShowRentPrice = function () {
    $("#rPriceSpan").css("display", "");
    $("#sPriceSpan").css("display", "none");
    $("#sPriceSpan #salePrice").val("");
};

//房源状态下拉列表数据加载 20160108 xingyk修改
//proertyFollow.percode 当前用户权限编码
//statusstr 当前房源状态
//selector 下拉列表ID
// 300是预定 700是资料盘
//2017801  liuxd修改
//状态变更为 有效、预定、无效、暂停
proertyFollow.statusOptions = function (statusstr, selector) {
    var data = PropertyStatusFilter.PropertyStatus;//所有房源状态
    var percode = $("#hidPermissions").val();//获取当前用户角色权限Code
    //当前房源状态为有效
    if (statusstr == "有效") {
        if (percode.indexOf("Property.Status.ValidTurnOther.ALL") != "-1") {
            //设置显示行家成交
            $('#hidProstatus').val(statusstr);
            for (var i = 0; i < data.length; i++) {
                if ( (data[i].Code == "200" || data[i].Code == "400") && data[i].Name != statusstr) {
                    $(selector).append("<option value='" + data[i].Value   + "' data-category = '" + data[i].Category + "'>" + data[i].Name + "</option>");
                }
            }
        }
          if (percode.indexOf("Property.Status.ValidTurnReserve.ALL") != "-1") {
            for (var i = 0; i < data.length; i++) {
                if (data[i].Code == "300" && data[i].Name != statusstr) {
                    $(selector).append("<option value='" + data[i].Value + "'>" + data[i].Name + "</option>");
                }
            }
        }
    }
        //当前状态为预定
    else if (statusstr == "预定") {
        if (percode.indexOf("Property.Status.ReserveTurnValid.ALL") != "-1") {
            for (var i = 0; i < data.length; i++) {
                if ((data[i].Code == "100"  ) && data[i].Name != statusstr) {
                    $(selector).append("<option value='" + data[i].Value + "' data-category = '" + data[i].Category + "'>" + data[i].Name + "</option>");
                }
            }
        }
    }
        //当前状态为其他状态
    else   {
        for (var i = 0; i < data.length; i++) {
            if ((data[i].Code == "100" || data[i].Code == "200" || data[i].Code == "400") && data[i].Name != statusstr) {
                $(selector).append("<option value='" + data[i].Value + "'>" + data[i].Name + "</option>");
            }
        }

    }

};

//增加状态模版
proertyFollow.addTurn = function (e, defaultStatusId, container) {
    if ($("#divFollowContent #spanUpdataStatus").find(".updataStatusCount").length >= 1) {
        return false;
    }

    $(container).append($("#divTempTurnStauts").html());
    if (defaultStatusId) {
        $(defaultStatusId).html($("#parPropertyStatus").val().split('=')[1]);
    }
    proertyFollow.statusOptions($('input.btnValues').attr("status"), "#divFollowContent #targetPropertyStatusKeyId3");
};

//增加联系人模版
proertyFollow.addTrustor = function (e, container) {
    if ($("#divFollowContent").find(".contactsRemark").length >= 3) {
        $.OKDialogAgency('<div class="tc">最多可添加3个联系人，如需添加，请删除一个联系人！</div>');
        return false;
    }
    $(container).append($("#TrustorTypeKeyIdtmp").html());
    //给动态添加的联系人限制备注填写的字数
    $(".contactsRemark").each(function () {
        $.inputStatistics2($(this));
    });
    var TrustorGender = null;
    TrustorGender = $("#divFollowContent select[name=TrustorGenderKeyId]").last();
    TrustorGender.empty();
    TrustorGender.append('<option selected="" value="-1">请选择</option>');
    dataBind.bindOption(23, TrustorGender);
};

proertyFollow.delContact = function (e) {
    $(e).parent().remove();
};

//添加跟进成功后调用的方法
$('body').append('<div id="loaderMask" style="width: 100%; height: 100%; position: fixed; z-index: 50; top: 0px; left: 0px; overflow: hidden;"></div>');
proertyFollow.addResult = function (data) {
    if (data == "ok") {
        $.OKDialogAgency('<div class="tc">添加成功！</div>', '提示', function () {
            var urlParamters = $('#parPropertyKeyId').val() + '&' + $('#parPropertyNo').val() + '&' + $('#parSalePrice').val() + '&' + $('#parSquare').val() + '&' + $('#parEstateName').val();
            urlParamters += "&delFollowDeparment=" + $("#hidDelFollowDeparment").val() + "&haveTopFollowRight=" + $("#hidHaveTopFollowRight").val() + "&haveAddFollowRight=" + $("#hidHaveAddFollowRight").val() + "&haveConfirmFollowRight=" + $("#hidHaveConfirmFollowRight").val();
            urlParamters += "&radom=" + Math.random();
            $.get("/property/proerty-detail-follow?" + urlParamters, function (data2) {
                $('#contentdiv').html(data2);
                proertyFollow.init();
            });
        });
    } else if (data == "oknew") {
        $("#parPropertyStatus").val("PropertyStatus=有效");
        $.OKDialogAgency('<div class="tc">添加成功！</div>', '提示', function () {
            var urlParamters = $('#parPropertyKeyId').val() + '&' + $('#parPropertyNo').val() + '&' + $('#parSalePrice').val() + '&' + $('#parSquare').val() + '&' + $('#parEstateName').val();
            urlParamters += "&delFollowDeparment=" + $("#hidDelFollowDeparment").val() + "&haveTopFollowRight=" + $("#hidHaveTopFollowRight").val() + "&haveAddFollowRight=" + $("#hidHaveAddFollowRight").val() + "&haveConfirmFollowRight=" + $("#hidHaveConfirmFollowRight").val();
            urlParamters += "&radom=" + Math.random();
            $.get("/property/proerty-detail-follow?" + urlParamters, function (data2) {
                $('#contentdiv').html(data2);
                proertyFollow.init();
            });
        });
    }
    else {
        $.OKDialogAgency('<div class="tc">' + data + '</div>');
        $("#divFollowContent input[type=submit]").removeAttr("disabled");
    }
    other.hideLoaderMask();
};
$("#loaderMask").remove();

proertyFollow.getEstateUrl = function () {
    return "/property/user-auto-complete-obtain-ajax";
};

//添加开盘人
proertyFollow.appendOpeningPersonClickEvent = function () {
    $.dialog({
        id: "AddRecommenddialog",
        lock: true,
        title: "添加开盘人",
        background: "#808080",
        content: '<div class="info-list">开 盘 人：<input type="text" id="txtOpeningPersonName" class="ipt" title="输入姓名并从提示中选择   "><input type="hidden" id="hidOpeningPersonKeyId"><input type="hidden" id="hidOpeningDeparmentName"><input type="hidden" id="hidOpeningDeparmentKeyId">&nbsp;<a id="btnOpeningPerson" class="vm">增加</a></div>'
    });
    $("#btnOpeningPerson").bind("click", function () {
        //原来是长度小于2，不知道什么原因
        if ($('#hidOpeningPersonKeyId').val() == "") {
            $.OKDialogAgency('<div class="tc">请从智能提示中选择开盘人！</div>');
            return false;
        }
        var openingPersonName = $("#txtOpeningPersonName").val();
        var openingPersonKeyId = $("#hidOpeningPersonKeyId").val();
        var openingDeparmentName = $("#hidOpeningDeparmentName").val();
        var openingDeparmentKeyId = $("#hidOpeningDeparmentKeyId").val();
        var isRepeatOpening = false;
        //判断要添加的联系人是否重复
        $("#spanAddOpeningPerson").find("input[name=openingPersonKeyId]").each(function () {
            if ($(this).val() == openingPersonKeyId) {
                isRepeatOpening = true;
                return;
            }
        });
        if (isRepeatOpening) {
            $.OKDialogAgency('<div class="tc">不能重复添加开盘人！</div>');
            return false;
        }
        if ($("#spanAddOpeningPerson").find("input[name=openingPersonKeyId]").length > 2) {
            $.OKDialogAgency('<div class="tc">开盘人最多增加3个！</div>');
            return false;
        }
        //清空开盘人信息与关联隐藏域
        $("#txtOpeningPersonName").val("");
        $("#hidOpeningPersonKeyId").val("");
        var test = $('#spanAddOpeningPerson').html();
        test += '<span class="l">' + openingPersonName + '<a>' + '<i class="fclose" onclick="proertyFollow.DelContactsClickEvent(this);">×</i></a><input type="hidden" name="openingPersonName" value="' + openingPersonName + '" /><input type="hidden" name="openingPersonKeyId" value="' + openingPersonKeyId + '" /><input type="hidden" name="openingDepName" value="' + openingDeparmentName + '" /><input type="hidden" name="openingDepKeyId" value="' + openingDeparmentKeyId + '" /></span>';
        $('#spanAddOpeningPerson').html(test);
    });

    //初始化新开盘人查找方式
    EmployeePrompt.getDepartAndEmployeeByInput(null, null, "txtOpeningPersonName", "hidOpeningPersonKeyId", false, "private", 1, "请选择开盘人", null, null, null, null, function (item) { if (item.DepartmentKeyId) { $("#hidOpeningDeparmentKeyId").val(item.DepartmentKeyId); } if (item.DepartmentName) { $("#hidOpeningDeparmentName").val(item.DepartmentName); } });
};

//添加提醒人
proertyFollow.appendContactsClickEvent = function () {
    $.dialog({
        id: "AddRecommenddialog",
        lock: true,
        title: "添加提醒人",
        background: "#808080",
        content: '<div class="info-list">联 系 人：<input type="text" id="txtContactsName" class="ipt" title="输入姓名并从提示中选择   "><input type="hidden" id="hidContactsKeyId"><input type="hidden" id="hidDeparmentName"><input type="hidden" id="hidDeparmentKeyId">&nbsp;<a id="btnAddContacts" class="vm">增加</a></div><div class="info-list">联系部门：<input type="text" id="txtContactsDepartment" class="ipt" title="输入部门并从提示中选择"><input type="hidden" id="hidContactsDepartmentKeyId">&nbsp;<a id="btnAddDepartment" class="vm">增加</a></div>'
    });
    $("#btnAddContacts").bind("click", function () {
        //原来是长度小于2，不知道什么原因
        if ($('#hidContactsKeyId').val() == "") {
            $.OKDialogAgency('<div class="tc">请从智能提示中选择提醒人！</div>');
            return false;
        }
        var contactsName = $("#txtContactsName").val();
        var contactsKeyId = $("#hidContactsKeyId").val();
        var contactsDepName = $("#hidDeparmentName").val();
        var contactsDepKeyId = $("#hidDeparmentKeyId").val();
        var isRepeatContacts = false;
        //判断要添加的联系人是否重复
        $("#spanAddContacts").find("input[name=contacts]").each(function () {
            if ($(this).val() == contactsKeyId) {
                isRepeatContacts = true;
                return;
            }
        });
        if (isRepeatContacts) {
            $.OKDialogAgency('<div class="tc">不能重复添加提醒人！</div>');
            return false;
        }

        //清空联系人信息与关联隐藏域
        $("#txtContactsName").val("");
        $("#hidContactsKeyId").val("");
        var test = $('#spanAddContacts').html();
        test += '<span class="l">' + contactsName + '<a>' + '<i class="fclose" onclick="proertyFollow.DelContactsClickEvent(this);">×</i></a><input type="hidden" name="contactsName" value="' + contactsName + '" /><input type="hidden" name="contactsKeyId" value="' + contactsKeyId + '" /><input type="hidden" name="contactsDepName" value="' + contactsDepName + '" /><input type="hidden" name="contactsDepKeyId" value="' + contactsDepKeyId + '" /></span>';
        $('#spanAddContacts').html(test);
    });
    //新增添加部门按钮
    $("#btnAddDepartment").bind("click", function () {
        if ($('#hidContactsDepartmentKeyId').val() == "") {
            $.OKDialogAgency('<div class="tc">请从智能提示中选择提醒部门！</div>');
            return false;
        }
        var contactsDepartName = $("#txtContactsDepartment").val();
        var contactsDepartKeyId = $("#hidContactsDepartmentKeyId").val();
        var isRepeatContacts = false;
        //判断要添加的联系人是否重复
        $("#spanAddContacts").find("input[name=contacts]").each(function () {
            if ($(this).val() == contactsDepartKeyId) {
                isRepeatContacts = true;
                return;
            }
        });
        if (isRepeatContacts) {
            $.OKDialogAgency('<div class="tc">不能重复添加提醒人！</div>');
            return false;
        }

        //清空联系人信息与关联隐藏域
        $("#txtContactsDepartment").val("");
        $("#hidContactsDepartmentKeyId").val("");
        var test = $('#spanAddContacts').html();
        test += '<span class="l">' + contactsDepartName + '<a>' + '<i class="fclose" onclick="proertyFollow.DelContactsClickEvent(this);">×</i></a><input type="hidden" name="contactsDepartKeyId" value="' + contactsDepartKeyId + '" /><input type="hidden" name="contactsDepartName" value="' + contactsDepartName + '" /></span>';
        $('#spanAddContacts').html(test);
    });

    //初始化提醒Ta的联系人查找方式
    EmployeePrompt.getDepartAndEmployeeByInput(null, null, "txtContactsName", "hidContactsKeyId", false, "private", 1, "请选择联系人", null, null, null, null, function (item) { if (item.DepartmentKeyId) { $("#hidDeparmentKeyId").val(item.DepartmentKeyId); } if (item.DepartmentName) { $("#hidDeparmentName").val(item.DepartmentName); } });
    EmployeePrompt.getDepartAndEmployeeByInput("txtContactsDepartment", "hidContactsDepartmentKeyId", null, null, true, "private", 1, null, "请选择部门", null, null, null, function (item) { if (item.DepartmentName) { $("#hidDeparmentName").val(item.DepartmentName); } });

};


//添加联系人(免扰设置在使用)
proertyFollow.appendNoCallContactsClickEvent = function () {
    $.dialog({
        id: "AddRecommenddialog",
        lock: true,
        title: "添加联系人",
        background: "#808080",
        content: '<input type="text" id="txtContactsName" class="ipt" title="输入姓名并从提示中选择"><input type="hidden" id="hidContactsKeyId"><input type="hidden" id="hidDeparmentName"><input type="hidden" id="hidDeparmentKeyId">&nbsp;<a id="btnAddContacts" class="vm">增加</a>'
    });
    $("#btnAddContacts").bind("click", function () {
        //原来是长度小于2，不知道什么原因
        if ($('#hidContactsKeyId').val() == "") {
            $.OKDialogAgency('<div class="tc">请从智能提示中选择联系人！</div>');
            return false;
        }
        var contactsName = $("#txtContactsName").val();
        var contactsKeyId = $("#hidContactsKeyId").val();
        var contactsDepName = $("#hidDeparmentName").val();
        var contactsDepKeyId = $("#hidDeparmentKeyId").val();
        var isRepeatContacts = false;
        //判断要添加的联系人是否重复
        $("#spanAddContacts").find(":hidden[name=contactsKeyId]").each(function () {
            var curUserKeyId = $(this).val();
            var curDeptKeyId = $(this).parent().find(":hidden[name=contactsDepKeyId]").val();
            if (curUserKeyId == contactsKeyId && curDeptKeyId == contactsDepKeyId) {
                isRepeatContacts = true;
                return;
            }
        });
        if (isRepeatContacts) {
            $.OKDialogAgency('<div class="tc">不能重复添加联系人！</div>');
            return false;
        }

        //清空联系人信息与关联隐藏域
        $("#txtContactsName").val("");
        $("#hidContactsKeyId").val("");
        $("#hidDeparmentName").val("");
        $("#hidDeparmentKeyId").val("");
        var test = $('#spanAddContacts').html();
        test += '<span class="l">' + contactsName + '<a>' + '<i class="fclose" onclick="proertyFollow.DelContactsClickEvent(this);">×</i></a><input type="hidden" name="contactsName" value="' + contactsName + '" /><input type="hidden" name="contactsKeyId" value="' + contactsKeyId + '" /><input type="hidden" name="contactsDepName" value="' + contactsDepName + '" /><input type="hidden" name="contactsDepKeyId" value="' + contactsDepKeyId + '" /></span>';
        $('#spanAddContacts').html(test);
    });
    //初始化提醒Ta的联系人查找方式
    EmployeePrompt.getDepartAndEmployeeByInput(null, null, "txtContactsName", "hidContactsKeyId", false, "private", 1, "请选择联系人", null, null, null, null, function (item) { if (item.DepartmentName) { $("#hidDeparmentName").val(item.DepartmentName); } if (item.DepartmentKeyId) { $("#hidDeparmentKeyId").val(item.DepartmentKeyId); } });
};

//删除联系人
proertyFollow.DelContactsClickEvent = function (ele) {
    $(ele).parent().parent().remove();
};
proertyFollow.check = function () {
    var flag = true;
    if ($("#TargetPropertyStatusKeyId1") && $("#TargetPropertyStatusKeyId1").val() == "207c3b74-158c-4852-95f6-a5b577b5d4e2") {
        if ($("#txtContractorName").val() == "") {
            $("#txtContractorName").addClass("checkError");
            if ($("#txtContractorName").next(".wrong").length <= 0) {
                $("#txtContractorName").after(agencyVerify.greatErrorHtml($("#txtContractorName"), '此项必填'));
            }
            flag = false;
        }

    }
    if ($("#txtTurnEmployeeName").val() == "") {
        $("#txtTurnEmployeeName").addClass("checkError");
        if ($("#txtTurnEmployeeName").next(".wrong").length <= 0) {
            $("#txtTurnEmployeeName").after(agencyVerify.greatErrorHtml($("#txtTurnEmployeeName"), '此项必填'));
        }
        flag = false;
    }
    return flag;
};
//列表页转盘提交操作,code为60
proertyFollow.listTurnEstateSubmit = function (e) {
    $(".aui_dialog input[name=foltype]").val(dataBind.getKeyIdByTypeAndCode("29", "60") + "," + "60");
    //if ($("#txtTurnDepartName").val() == "") {
    //    $("#txtTurnDepartName").focus();
    //    return false;
    //}
    proertyFollow.check();
    if ($("#TargetPropertyStatusKeyId1") && $("#TargetPropertyStatusKeyId1").val() == "207c3b74-158c-4852-95f6-a5b577b5d4e2") {
        $("div.aui_content input[notnull=notNull]").blur();
        if ($("#addFollowForm .wrong").length == 0) {
            //$.OKCancelDialogAgency('<div class="tc">请确认已将此房源转给成交人，否则修改为预定状态后，将看不到此房源！</div>', '提示', true, function () {
            proertyFollow.formBegin();

            //}, true);
            // return false;
        }
    } else {
        if ($("#addFollowForm .wrong").length == 0) {
            proertyFollow.formBegin();
        }
    }
    //if ($(".btnValues:checked").attr("statuscode") == "3") {
    //    $.OKDialogAgency("预订房源不能修改房源状态！","提示");
    //    return false;
    //}  
}

proertyFollow.formBegin = function () {
    if ($("#btnTurnSubmit").attr("disabled") == "disabled") {
        return true;
    }
    else {
        if ($("#addFollowForm").find(".wrong:visible").length == 0) {
            $.OKCancelDialogAgency('<div class="tc">确定将所选房源转至' + $("div.info-list #txtTurnDepartName").val() + $("div.info-list #txtTurnEmployeeName").val() + '</div>', '提示', true, function () {
                other.buttonDisable('#btnTurnSubmit', 'disabled');
                $("#addFollowForm").submit();
            }, null);
            return false;
        } else { return false; }
    }
}

//列表页和房源详细更改状态操作,更改状态是个操作类型，code为70
proertyFollow.listTurnStatusSubmit = function () {
    //if ($("#addFollowForm").find(".wrong:visible").length == 0 ) {
    //    $("#btn_upstatus").attr("disabled", "disabled");
    //}
    var radioval2 = $("#expertTransactionTypeKeyId2 input:radio[name='ExpertTransaction']:checked").val();
    var radioval = $("#expertTransactionTypeKeyId input:radio[name='ExpertTransaction']:checked").val();
    var ischecked = $("input[name='TrustorDelay']").is(':checked');
    if ($("#hidProstatus").val() == "有效" && $("#TargetPropertyStatusKeyId2").val() != "207c3b74-158c-4852-95f6-a5b577b5d4e2") {
        if ((radioval == null || radioval == "undefined") && (radioval2 == null || radioval2 == "undefined") && !ischecked) {
            $.OKDialogAgency('<div class="tc">行家成交和业主停售（租）必填一项！</div>');
            return false;
        }
    }
    if ($("#TargetPropertyStatusKeyId2").children().length <= 0) {
        $.OKDialogAgency('<div class="tc">暂无修改权限！</div>');
        return false;
    }
    else {
        $("#CHANGESTATUSdivTextarea").blur();
        if ($("#TargetPropertyStatusKeyId2") && $("#TargetPropertyStatusKeyId2").val() == "207c3b74-158c-4852-95f6-a5b577b5d4e2") {
            $("div.aui_content input[notnull=notNull]").blur();
            if ($("#txtContractorName").val() == "") {
                $("#txtContractorName").focus();
                $("#txtContractorName").addClass("checkError");
                if ($("#txtContractorName").next(".wrong").length <= 0) {
                    $("#txtContractorName").after(agencyVerify.greatErrorHtml($("#txtContractorName"), '此项必填'));
                }
                return false;
            }
            //$.OKCancelDialogAgency('<div class="tc">请确认已将此房源转给成交人，否则修改为预定状态后，将看不到此房源！</div>', '提示', function () {
            //$("#btn_upstatus").removeAttr("disabled");
            //}, function () {
            if ($("#addFollowForm").find(".wrong").length == 0) {
                $(".aui_dialog input[name=foltype]").val(dataBind.getKeyIdByTypeAndCode("29", "70") + "," + "70");
                $("#addFollowForm").submit();
                $("#btn_upstatus").attr("disabled", "disabled");

                $("#loaderMask").remove();

            }
            //}, function () {
            //$("#btn_upstatus").removeAttr("disabled");
            //});

        } else {
            if ($("#addFollowForm").find(".wrong").length == 0) {
                $(".aui_dialog input[name=foltype]").val(dataBind.getKeyIdByTypeAndCode("29", "70") + "," + "70");
                $("#addFollowForm").submit();
                $("#btn_upstatus").attr("disabled", "disabled");

                $("#loaderMask").remove();

            }
        }
    }

}
//公盘列表页申请转盘操作,code为30
proertyFollow.listTurnMeSubmit = function () {
    $(".aui_dialog input[name=foltype]").val(dataBind.getKeyIdByTypeAndCode("29", "30") + "," + "30");
}
//表单提交前数据检测
proertyFollow.beginCheck = function () {
    var checkRes = true;
    //如果是叫价申请就得验证售价和租价
    if ($("#divFollowContent #btnApplyPrice").length > 0) {
        if (!$("#divFollowContent [name=SalePrice]").val() && !$("#divFollowContent [name=RentPrice]").val()) {
            $.OKDialogAgency('<div class="tc">售价或租价必填一个！</div>', "提示", function () {
                $("#CALLAPPLYdiv .btn-lg-red").removeAttr("disabled");
            }, function () {
                $("#CALLAPPLYdiv .btn-lg-red").removeAttr("disabled");
            });
            checkRes = false;
        }
    }

    if ($("#divFollowContent [name=TrustorGenderKeyId]").length > 0) {
        var tempResult = true;
        $("#divFollowContent [name=TrustorGenderKeyId]").each(function () {
            if ($(this).val() == "-1") {
                tempResult = false;
            }
        });
        if (!tempResult) {
            $.OKDialogAgency('<div class="tc">请选择称谓！</div>');
            checkRes = false;
        }
    }
    return checkRes;
};

//添加常用跟进类型值
proertyFollow.commonFollowClick = function (ele) {
    var tempValue = $("#divFollowContent #txtClenTextarea").val();
    $("#divFollowContent #txtClenTextarea").val(tempValue + $(ele).attr("myvalue"));

    //proertyFollow.commonFollowToggle($("#divFollowContent #btnOtherSets"));
    //yangjj添加 修复选择常用跟进后，跟进内容剩余字符数字不变的bug
    var len = $("#divFollowContent #txtClenTextarea").val().length;
    $("#txtClenTextarea").next().find(".red").html(200 - len);
    $("#txtClenTextarea").focus();
    $("#txtClenTextarea").parent().parent().parent().find(".pd-other-sets-box").hide();
};
//手机是否存在的验证方法
proertyFollow.mobileCheck = function () {
    var currentinput = this;
    var temspan = $(this).next();
    if (temspan.attr("type") == "sameCheckAjax") {
    }
    else if (temspan.next().attr("type") == "sameCheckAjax") {
        temspan = temspan.next();
    }
    else {
        return;
    }

    if ($(this).val().length != 11) {
        temspan.css("display", 'none');
        temspan.html("");
        return false;
    }
    temspan.css("display", '');
    temspan.html("<img src='/static/app/img/loading.gif'/>");
    var reqData = {
        'mobile': $(this).val(),
        "PropertyKeyId": $("#hidPropertyKeyId").val()
    };
    $.AjaxAgency('/Property/same-mobile-check-ajax', reqData, function (data) {
        if (data == "ok") {
            temspan.html("");
            temspan.css("display", 'none');
            $(currentinput).removeClass("checkError2");
            return;
        }
        if (data == "exception") {
            $.OKDialogAgency('<div class="tc">检查错误，请重新输入手机号！</div>');
            return;
        }
        if (data.indexOf("该号码已存在") != -1) {
            //var tempData = data.split('==');
            //temspan.html(tempData[1] + '！<a href="/property/details?keyId=' + tempData[0] + '" target="_blank">去看看</a>');
            //判断是否存在别的验证，如果存在，则不出现
            var temspanother = $(currentinput).next();
            if (temspanother.attr("class") == "wrong" && temspan.attr("type") != "sameCheckAjax") {

            }
            else {
                temspan.html("该号码已存在!");
                temspan.css("display", '');
                $(currentinput).addClass("checkError2");
            }
        }

    });

}

//座机是否存在的验证方法 hjx 2015-06-11 17:07
proertyFollow.telphoneCheck = function () {
    var currentinput = this;
    //当前父级
    var temparent = $(this).parent();
    var telphone1 = temparent.find("input[telphone=telphone1]").val();
    var telphone2 = temparent.find("input[telphone=telphone2]").val();
    var telphone3 = temparent.find("input[telphone=telphone3]").val();
    var tel = telphone1 + "-" + telphone2 + "-" + telphone3;
    var temspan = temparent.find("[type=sameCheckAjax]");
    if (tel != "--") {
        temspan.css("display", '');
        temspan.html("<img src='/static/app/img/loading.gif'/>");
        var reqData = {
            'tel': tel,
            "PropertyKeyId": $("#hidPropertyKeyId").val()
        };
        $.AjaxAgency('/Property/same-tel-check-ajax', reqData, function (data) {
            if (data == "ok") {
                temspan.html("");
                temspan.css("display", 'none');
                return;
            }
            else if (data.indexOf("该号码已存在") != -1) {
                temspan.html("该号码已存在!");
                temspan.css("display", '');
            }
        });
    }
}

//在详细页跟进切换时，用来存放临时数据，如跟进内容，提醒他
proertyFollow.temparray = [];
//在详细页跟进切换时，用来存放当前选择的跟进code
proertyFollow.temptypecode = "";

proertyFollow.init = function () {
    //加载跟进内容
    //dataBind.bindRadioByPropertyCondition(29, "#followType", "foltype", "1", $("#hidJsonValue").val());    
    dataBind.bindRadioFollowType(29, "#followType", "foltype", "1", $("#hidJsonValue").val(), $("#parPropertyStatus").val(), $("#parTrustType").val());
    //判断是否为有效，预定房源，调整跟进类型的排列顺序
    if ($("#currentStatusStr").html() == '有效' || $("#currentStatusStr").html() == '预定') {
        $('input[itemcode="2030"],input[itemcode="2110"]').parent().addClass('l');
    }
    else {
        $('input[itemcode="10"],input[itemcode="2110"]').parent().addClass('l');
    }
    //加载常用跟进内容
    dataBind.bindLiLink(64, ".commonFollowType", "proertyFollow.commonFollowClick(this);");
    dataBind.bindOption(29, "#selFollowType");
    //判断当前房源交易类型,若为租售，则隐藏新开盘跟进类型选项。
    var trustType = $("#parTrustType").val();
    if (trustType == "BOTH" && $("#currentStatusStr").html() == '有效') {
        $("#writeFollow [name=foltype]").each(function () {
            if ($(this).attr("itemcode") == "2110") {
                $(this).parent("label").hide();
            }
        });
    }
    $("#btnSubmit").bind("click", function () {
        var temf = $("#txtSquareFrom").val();
        var temt = $("#txtSquareTo").val();
        if (temf != "" && temt != "") {
            if (timehelper.parseDate(temf) > timehelper.parseDate(temt)) {
                $("#txtSquareTo").val(temf);
                $("#txtSquareFrom").val(temt);
            }
        }
    });

    dataBind.bindOption(21, "select[name=TrustorTypeKeyId]"); //委托人类型

    $("#NEWOPENINGdiv input[type='submit']").unbind("click");
    $("#NEWOPENINGdiv input[type='submit']").bind("click", function () {
        if ($("#currentStatusStr").html() != "预定") {
            $("#currentStatusStr").html("有效");
        };
    });

    //房源清洗,新增业主电话,申请转盘---内容切换
    $("#writeFollow [name=foltype]").click(function () {
        $('#btnOtherSetsBox1').css('display', 'none');
        $('#sPriceSpan,#rPriceSpan').css('display', 'none');
        var tempItemCode = $(this).attr("itemcode");
        //首先判断一下当前的code是不是普通code(就是一个文本框没有特别逻辑),如果是普通code,要把文本和提醒他存起来
        if (proertyFollow.temptypecode != "" && proertyFollow.temptypecode != 10 && proertyFollow.temptypecode != 20 && proertyFollow.temptypecode != 30 && proertyFollow.temptypecode != 1230 && proertyFollow.temptypecode != 60 && proertyFollow.temptypecode != 70) {
            var temflag = true;
            for (var i = 0; i < proertyFollow.temparray.length; i++) {
                if (proertyFollow.temparray[i].code == proertyFollow.temptypecode) {
                    proertyFollow.temparray[i].text = $("#divFollowContent #INFOSUPPLYdivTextarea").val();
                    proertyFollow.temparray[i].contect = $("#divFollowContent #spanAddContacts").html();
                    temflag = false;
                    break;
                }
            }
            if (temflag) {
                proertyFollow.temparray.push({ code: proertyFollow.temptypecode, text: $("#divFollowContent #INFOSUPPLYdivTextarea").val(), contect: $("#divFollowContent #spanAddContacts").html() });
            }
        }
        var teminputs = $("#divFollowContent").find("input[type=text]");
        teminputs.each(function () {
            this.setAttribute("value", this.value);
        });
        var temoption = $("#divFollowContent").find("option");
        temoption.each(function () {
            if (this.selected) {
                this.setAttribute("selected", this.selected);
            }
        });

        $("#followTypeTmp").append($("#divFollowContent").html());
        $("#divFollowContent").html("");
        //yjj添加 解决报黄时，选择常用跟进不计数
        $("#txtClenTextarea").blur(function () {
            $.inputStatistics("txtClenTextarea", 200);
        });

        //新开盘
        if (tempItemCode == "2110") {
            $("#NEWOPENINGdiv").find(".btn-lg-red").removeAttr("disabled");
            $("#NEWOPENINGdiv #spanAddContactsModel").empty();
            $.inputStatistics("OPENINGRESONdivTextarea", 200);
            var trustType = $("#parTrustType").val();
            var propertyStatus = $("#currentStatusStr").html();
            if (trustType != null && trustType != "") {
                $("#divFollowContent").append($("#NEWOPENINGdiv"));
                if (trustType == "BOTH" && propertyStatus != '有效') {
                    $("#hidTrustType").val("BOTH");
                    $("#hidOpeningType").val(4);
                    $("#newToRent").show();
                    $("#newToSale").show();
                    $("#newToRent a").removeClass("cur");
                    $("#newToSale a").addClass("cur");
                    $("#rentToSale").hide();
                    $("#saleToRent").hide();
                    $("#sPriceSpan").css("display", "");
                    $("#rentPrice").removeAttr("notnull");
                }
                else if (trustType == "RENT") {
                    $("#hidTrustType").val("RENT");
                    $("#newToSale").hide();
                    $("#rentToSale").show();
                    $("#saleToRent").hide();
                    if (propertyStatus == "有效") {
                        $("#newToRent").hide();
                        $("#rentToSale a").addClass("cur");
                        $("#newToRent a").removeClass("cur");
                        $("#hidOpeningType").val(1);
                        $("#sPriceSpan").css("display", "");
                        $("#rentPrice").removeAttr("notnull");
                    } else {
                        $("#newToRent").show();
                        $("#rentToSale a").removeClass("cur");
                        $("#newToRent a").addClass("cur");
                        $("#rPriceSpan").css("display", "");
                        $("#salePrice").removeAttr("notnull");
                        $("#hidOpeningType").val(3);
                    }
                }
                else if (trustType == "SALE") {
                    $("#hidTrustType").val("SALE");
                    $("#newToRent").hide();
                    $("#rentToSale").hide();
                    $("#saleToRent").show();
                    if (propertyStatus == "有效") {
                        $("#newToSale").hide();
                        $("#saleToRent a").addClass("cur");
                        $("#newToSale a").removeClass("cur");
                        $("#rPriceSpan").css("display", "");
                        $("#salePrice").removeAttr("notnull");
                        $("#hidOpeningType").val(2);
                    } else {
                        $("#newToSale").show();
                        $("#saleToRent a").removeClass("cur");
                        $("#newToSale a").addClass("cur");
                        $("#sPriceSpan").css("display", "");
                        $("#rentPrice").removeAttr("notnull");
                        $("#hidOpeningType").val(4);
                    }
                }
                $('#spanAddOpeningPerson').html("");
                var test = $('#spanAddOpeningPerson').html();
                test += '<span class="l">' + $("#parUserName").val() + '<a>' + '<i class="fclose" onclick="proertyFollow.DelContactsClickEvent(this);">×</i></a><input type="hidden" name="openingPersonName" value="' + $("#parUserName").val() + '" /><input type="hidden" name="openingPersonKeyId" value="' + $("#parUserKeyId").val() + '" /><input type="hidden" name="openingDepName" value="' + $("#parDeptName").val() + '" /><input type="hidden" name="openingDepKeyId" value="' + $("#parDeptKeyId").val() + '" /></span>';
                $('#spanAddOpeningPerson').html(test);

                $("#NEWOPENINGdiv [name=follow]").unbind("click");
                $("#NEWOPENINGdiv [name=follow]").bind("click", function () {
                    var followId = $(this).attr("id");
                    //租开售
                    if (followId == "rentToSale") {
                        $("#hidOpeningType").val(1);
                        $("#rentToSale a").addClass("cur");
                        $("#newToRent a").removeClass("cur");
                        $("#saleToRent a").removeClass("cur");
                        $("#newToSale a").removeClass("cur");
                        $("#sPriceSpan").css("display", "");
                    }
                        //售开租
                    else if (followId == "saleToRent") {
                        $("#hidOpeningType").val(2);
                        $("#saleToRent a").addClass("cur");
                        $("#newToSale a").removeClass("cur");
                        $("#rentToSale a").removeClass("cur");
                        $("#newToRent a").removeClass("cur");
                        $("#rPriceSpan").css("display", "");
                    }
                        //新开租
                    else if (followId == "newToRent") {
                        $("#hidOpeningType").val(3);
                        $("#saleToRent a").removeClass("cur");
                        $("#rentToSale a").removeClass("cur");
                        $("#newToSale a").removeClass("cur");
                        $("#newToRent a").addClass("cur");
                        $("#rPriceSpan").css("display", "");
                    }
                        //新开售
                    else if (followId == "newToSale") {
                        $("#hidOpeningType").val(4);
                        $("#rentToSale a").removeClass("cur");
                        $("#newToRent a").removeClass("cur");
                        $("#saleToRent a").removeClass("cur");
                        $("#newToSale a").addClass("cur");
                        $("#sPriceSpan").css("display", "");
                    }
                });

                $("#selGenderKeyId").unbind("change");
                $("#selGenderKeyId").bind("change", function () {
                    $('#hidGender').val($("#selGenderKeyId  option:selected").text());
                });
            } else {
                $.OKDialogAgency('<div class="tc">该房源没有交易类型！</div>', '提示', function () {
                    var urlParamters = $('#parPropertyKeyId').val() + '&' + $('#parPropertyNo').val() + '&' + $('#parSalePrice').val() + '&' + $('#parSquare').val() + '&' + $('#parEstateName').val();
                    urlParamters += "&delFollowDeparment=" + $("#hidDelFollowDeparment").val() + "&haveTopFollowRight=" + $("#hidHaveTopFollowRight").val() + "&haveAddFollowRight=" + $("#hidHaveAddFollowRight").val() + "&haveConfirmFollowRight=" + $("#hidHaveConfirmFollowRight").val();
                    urlParamters += "&radom=" + Math.random();
                    $.get("/property/proerty-detail-follow?" + urlParamters, function (data2) {
                        $('#contentdiv').html(data2);
                        proertyFollow.init();
                    });
                });
            }
        }
        else if (tempItemCode == "10") {
            $("#CLEANdiv").find(".btn-lg-red").removeAttr("disabled");
            $.inputStatistics("txtClenTextarea", 200);
            $("#divFollowContent").append($("#CLEANdiv"));
            //常用跟进切换
            $("#btnOtherSetsBox").unbind("hover");
            $("#btnOtherSetsBox").hover(function () {
                $(this).find("ul").show();
                $(this).find("i").addClass("gray-down-arrow-on");
            }, function () {
                $(this).find("ul").hide();
                $(this).find("i").removeClass("gray-down-arrow-on");
            });
            $('#btnOtherSetsBox1').css('display', 'block');
            //为洗盘拼接字符串
            $('.spfollowtype').unbind("click");
            $('.spfollowtype').bind("click", function (data) {
                if ($("#txtClenTextarea").parent().find($(".wrong:visible")) && $("#txtClenTextarea").parent().find($(".wrong:visible")).length > 0) {
                    $("#txtClenTextarea").removeClass("checkError");
                    $("#txtClenTextarea").next().hide();
                    $("#txtClenTextarea").attr("hasValue", true);
                }
                if ($(this).text() == "不租不售") {
                    $("#txtClenTextarea").val($("#txtClenTextarea").val() + "【不租不售】,原因:");
                    if ($("#txtClenTextarea").val() == "") {
                        $("#txtClenTextarea").addClass("checkError");
                        $("#txtClenTextarea").next().show();
                    }
                }
                else {
                    $("#txtClenTextarea").val($("#txtClenTextarea").val() + "【" + $(this).text() + "】");
                }
            });
        } else if (tempItemCode == "20") {
            $("#TRUSTORdiv").find(".btn-lg-red").removeAttr("disabled");
            $.inputStatistics("TRUSTORdivTextarea", 200);
            $.inputStatistics2(".contactsRemark");
            $("#selTrustorGenderKeyId").empty();
            $("#selTrustorGenderKeyId").append('<option selected="" value="-1">请选择</option>');
            dataBind.bindOption(23, "#selTrustorGenderKeyId");
            $("#divFollowContent").append($("#TRUSTORdiv"));
        } else if (tempItemCode == "30") {
            $.inputStatistics("TURNdivTextarea", 200);
            $("#divFollowContent").append($("#TURNdiv"));

        } else if (tempItemCode == "2030") {
            $("#INFOSUPPLYdiv").find(".btn-lg-red").removeAttr("disabled");
            $.inputStatistics("INFOSUPPLYdivTextarea", 200);
            $("#divFollowContent").append($("#INFOSUPPLYdiv"));
            $("#divFollowContent #INFOSUPPLYdivTextarea").val("");
            $("#divFollowContent #spanAddContacts").html("");
            for (var i = 0; i < proertyFollow.temparray.length; i++) {
                if (proertyFollow.temparray[i].code == tempItemCode) {
                    $("#divFollowContent #INFOSUPPLYdivTextarea").val(proertyFollow.temparray[i].text);
                    $("#divFollowContent #spanAddContacts").html(proertyFollow.temparray[i].contect);
                    break;
                }
            }
            $('#btnOtherSetsBox1').css('display', 'block');
            //为信息补充拼接字符串
            $('.lebfollowtype').unbind("click");
            $('.lebfollowtype').bind("click", function (data) {
                if ($("#INFOSUPPLYdivTextarea").parent().find($(".wrong:visible")) && $("#INFOSUPPLYdivTextarea").parent().find($(".wrong:visible")).length > 0) {
                    $("#INFOSUPPLYdivTextarea").removeClass("checkError");
                    $("#INFOSUPPLYdivTextarea").next().hide();
                    $("#INFOSUPPLYdivTextarea").attr("hasValue", true);
                }
                if ($(this).text() == "不租不售") {
                    $("#INFOSUPPLYdivTextarea").val($("#INFOSUPPLYdivTextarea").val() + "【不租不售】,原因:");
                }
                else {
                    $("#INFOSUPPLYdivTextarea").val($("#INFOSUPPLYdivTextarea").val() + "【" + $(this).text() + "】");
                }
            });
        }
        else if (tempItemCode == "2000") {
            $("#Proceduresdiv").find(".btn-lg-red").removeAttr("disabled");
            $("#selGenderKeyId").empty();
            $("#selGenderKeyId").append('<option selected="" value="-1">请选择</option>');
            dataBind.bindOption(23, "#selGenderKeyId");
            $("#divFollowContent").append($("#Proceduresdiv"));
            $.inputStatistics("ProceduresdivTextarea", 200);
            $("#selGenderKeyId").unbind("change");
            $("#selGenderKeyId").bind("change", function () {
                $('#hidGender').val($("#selGenderKeyId  option:selected").text());
            });
        }
        else if (tempItemCode == "1230") {
            $("#CALLAPPLYdiv").find(".btn-lg-red").removeAttr("disabled");
            $.inputStatistics("txtApplyPrice", 200);
            $("#divFollowContent").append($("#CALLAPPLYdiv"));
            if ($("#saleIcon").length > 0) {
                $("#salePriceSpan").show();
            }
            if ($("#rentIcon").length > 0) {
                $("#rentPriceSpan").show();
            }

            //售价
            $("#salePrice").unbind("keyup");
            $("#salePrice").bind("keyup", function () {
                var salePrice = other.trim($("#parSalePrice1").val());
                var newSalePrice = other.trim($(this).val());
                if (salePrice > 0 && newSalePrice != "") {
                    var saleResult = (parseFloat(newSalePrice - salePrice) / parseFloat(salePrice));
                    var num = new Number(saleResult);
                    saleResult = num * 100;
                    saleResult = saleResult.toFixed(2);
                    $("#salePer").text(saleResult + "%");
                    $("#hidSalePer").val(saleResult + "%");
                }
                else {
                    $("#salePer").text("");
                    $("#hidSalePer").val("");
                }
            });

            //租价
            $("#rentPrice").unbind("keyup");
            $("#rentPrice").bind("keyup", function () {

                var rentPrice = other.trim($("#parRentPrice1").val());
                var newRentPrice = other.trim($(this).val());
                if (rentPrice > 0 && newRentPrice != "") {
                    var rentResult = (parseFloat(newRentPrice - rentPrice) / parseFloat(rentPrice));
                    var num = new Number(rentResult);
                    rentResult = num * 100;
                    rentResult = rentResult.toFixed(2);
                    $("#rentPer").text(" " + rentResult + "%");
                    $("#hidRentPer").val(" " + rentResult + "%");
                }
                else {
                    $("#rentPer").text("");
                    $("#hidRentPer").val("");
                }
            });
            agencyVerify.nonnegativeInput("#divFollowContent [name=SalePrice],#divFollowContent [name=RentPrice]");
        } else if (tempItemCode == "60") {
            $.inputStatistics("TRUN2divTextarea", 200);
            $("#TargetPropertyStatusKeyId1").empty().append('<option value="-1">保持现状</option>');
            proertyFollow.statusOptions(currentStatusStr, "#TargetPropertyStatusKeyId1");
            $("#divFollowContent").append($("#TRUN2div"));
            if ($("#TargetPropertyStatusKeyId1").val() == "预订") {
                $.OKDialogAgency('<div class="tc">请选择一个审核状态进行保存</div>');
            }
            //初始化转部门和业务员方法
            EmployeePrompt.getDepartAndEmployeeByInput("txtTurnDepartName", "hidTurnDepartKeyId", "txtTurnEmployeeName", "hidTurnEmployeeKeyId", true, true, 1, null, null, true);

        } else if (tempItemCode == "70") {
            $.inputStatistics("CHANGESTATUSdivTextarea", 200);
            $("#currentStatus2").html($("#parPropertyStatus").val().split("=")[1]);
            $("#divFollowContent").append($("#CHANGESTATUSdiv"));
            $("#TargetPropertyStatusKeyId2").empty();
            proertyFollow.statusOptions(currentStatusStr, "#TargetPropertyStatusKeyId2");
        }
        else {
            $("#INFOSUPPLYdiv").find(".btn-lg-red").removeAttr("disabled");
            $.inputStatistics("INFOSUPPLYdivTextarea", 200);
            $("#divFollowContent").append($("#INFOSUPPLYdiv"));
            $("#divFollowContent #INFOSUPPLYdivTextarea").val("");
            $("#divFollowContent #spanAddContacts").html("");
            for (var i = 0; i < proertyFollow.temparray.length; i++) {
                if (proertyFollow.temparray[i].code == tempItemCode) {
                    $("#divFollowContent #INFOSUPPLYdivTextarea").val(proertyFollow.temparray[i].text);
                    $("#divFollowContent #spanAddContacts").html(proertyFollow.temparray[i].contect);
                    break;
                }
            }
        }
        //数据验证Start

        agencyVerify.notNullInput("#addFollowFormDetail", "#divFollowContent [notnull=notNull]", true, "blur");
        agencyVerify.mobileInput("#addFollowFormDetail", "#divFollowContent [mobile=Mobile]", true, "blur");
        agencyVerify.notdefaultSelect("#addFollowFormDetail", "#divFollowContent [name=TrustorGenderKeyId]", -1, "请选择联系人称谓", true);
        //数据验证End
        //逻辑结束后，把当前code存入全局变量
        proertyFollow.temptypecode = tempItemCode;
        //在切换的时候，把验证框都去了，不然会出现，明明有文字，还会有验证提示框的情况
        $("#divFollowContent .wrong:not([type=sameCheckAjax])").remove();
        $(".wrong[type=sameCheckAjax]").html("");
        $(".wrong[type=sameCheckAjax]").hide();
        $("#divFollowContent .checkError").removeClass("checkError");
        $("#divFollowContent .checkError2").removeClass("checkError2");
    });
    if ($("#currentStatusStr").html() == '有效' || $("#currentStatusStr").html() == '预定') {
        $($("#writeFollow [itemCode='2030']")[0]).click();
    }
    else {
        $($("#writeFollow [name=foltype]")[0]).click();
    }


    $("#addFollowFormDetail").bind("submit", function () {
        other.obsortRepeatSubmit("INFOSUPPLYdiv");
        other.obsortRepeatSubmit("TRUSTORdiv");
        other.obsortRepeatSubmit("NEWOPENINGdiv");
        other.obsortRepeatSubmit("SUPERVISEdiv");
        other.obsortRepeatSubmit("CALLAPPLYdiv");
        other.obsortRepeatSubmit("CLEANdiv");
        var re = true;
        $("#addFollowFormDetail span[type=sameCheckAjax]").each(function () {
            if ($(this).html() != "") {
                re = false;
            }
        });
        return re;
    });
    $("#cleanRad").click();

    //折行
    //$("#followGrid div[tag=content]").foldLine(true, 0);

    //置顶跟进
    $("#btnTop").bind("click", function () {
        var ids = "";
        var hasTop = false;
        var content = ""
        $("#followGrid input:checked").each(function () {
            if ($(this).parent().parent().find(".js_top").length > 0) {
                hasTop = true;
                return false;
            }
            ids += ($(this).val() + ',');
            content += $(this).attr("content");
        });
        var pid = $("#hidPropertyKeyId").val();
        if ($("#followGrid input:checked").length <= 0) {
            $.OKDialogAgency('<div class="tc">请选择跟进</div>');
            return;
        } else if (hasTop == true) {
            $.OKDialogAgency("您选择的跟进包含您已置顶的跟进，置顶失败！");
            return;
        }
        //判断权限
        //if (!PropertyFollowRight.CheckTopRightDedail()) {
        //    return;
        //}
        $.ajax({
            type: 'post',
            url: '/Property/property-follow-batch-mark-top-ajax',
            data: { 'keyids': ids, 'PropertyKeyId': pid, 'followContent': content },
            success: function (data) {
                if (data.PropertyBatchMarkTop.Flag) {
                    if (data.PropertyBatchMarkTop.OperateFlag) {
                        $.OKDialogAgency('<div class="tc">' + data.PropertyBatchMarkTop.SuccessInfo + '</div>', '提示', function () {
                            $("#hidrandom").val(Math.random);
                            $("#searchForm").submit();
                            $("#btnTop,#btnDel").removeClass("btn-blue2").addClass("btn-gray");
                        });
                    } else {
                        $.OKDialogAgency('<div class="tc">' + data.PropertyBatchMarkTop.FailedOperateReason + '</div>');
                    }

                } else {
                    $.OKDialogAgency('<div class="tc">' + data.PropertyBatchMarkTop.ErrorMsg + '</div>');
                }
            }
        });
    });

    //删除跟进
    $("#btnDel").bind("click", function () {
        var ids = "";
        $("#followGrid input:checked").each(function () { ids += ($(this).val() + ',') });
        if (!ids) {
            $.OKDialogAgency('<div class="tc">请选择跟进！</div>');
            return;
        }
        //判断权限
        //if (!PropertyFollowRight.CheckDelRightDedail()) {
        //    return;
        //}
        $.OKCancelDialogAgency('<div class="tc">确认删除该跟进信息吗？</div>', "删除跟进", true, function () {
            $.ajax({
                type: 'post',
                url: '/Property/property-follow-batch-remove-ajax',
                data: { 'keyids': ids, 'propertyKeyId': $("#hidPropertyKeyId").val() },
                success: function (data) {
                    if (data == "OK") {
                        $.OKDialogAgency('<div class="tc">删除成功</div>', '提示', function () {
                            $("#hidrandom").val(Math.random);
                            $("#searchForm").submit();
                        });
                    } else {
                        $.OKDialogAgency('<div class="tc">删除出错:' + data + '</div>');
                    }
                }
            });
        });
    });

    $("#btnConfirm").bind("click", function () {

        var ids = "";
        var IsConfirm = false;
        $("#followGrid input:checked").each(function () {
            if ($(this).parent().parent().find(".HasConfirmed").length > 0) {
                IsConfirm = true;
                return false;
            }
            ids += ($(this).val() + ',');
        });

        //$("#followGrid input:checked").each(function () { ids += ($(this).val() + ',') });
        if ($("#followGrid input:checked").length <= 0) {
            $.OKDialogAgency('<div class="tc">请选择跟进!</div>');
            return;
        } else if (IsConfirm) {
            $.OKDialogAgency('<div class="tc">您选择的跟进已确认！</div>');
            return;
        }

        $.OKCancelDialogAgency('<div class="tc">确认该跟进信息吗？</div>', "确认跟进", true, function () {
            $.ajax({
                type: 'post',
                url: '/Property/property-follow-batch-confirm-ajax',
                data: { 'keyids': ids, 'propertyKeyId': $("#hidPropertyKeyId").val() },
                success: function (data) {
                    if (data == "OK") {
                        $.OKDialogAgency('<div class="tc">确认成功</div>', '提示', function () {
                            $("#searchForm").submit();
                            $("#btnTop,#btnDel,#btnConfirm").removeClass("btn-blue2").addClass("btn-gray");
                        });
                    } else {
                        $.OKDialogAgency('<div class="tc">确认出错:' + data + '</div>');
                    }
                }
            })
        });
    });
};

proertyFollow.searchBefor = function () {
    $("#hidrandom").val(Math.random());
    window.pageStartTime = new Date();
    other.showLoaderMask();
};

